package com.macro.mall.service.impl;

import com.github.pagehelper.PageHelper;
import com.macro.mall.dto.BmsTourismProjectActivitiesApplicantDetail;
import com.macro.mall.dto.BmsTourismProjectActivitiesApplicantParam;
import com.macro.mall.mapper.BmsTourismProjectActivitiesApplicantMapper;
import com.macro.mall.model.BmsTourismProjectActivitiesApplicant;
import com.macro.mall.model.BmsTourismProjectActivitiesApplicantExample;
import com.macro.mall.service.BmsTourismProjectActivitiesApplicantService;
import org.apache.commons.compress.utils.Lists;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Service
public class BmsTourismProjectActivitiesApplicantServiceImpl implements BmsTourismProjectActivitiesApplicantService {

    @Autowired
    private BmsTourismProjectActivitiesApplicantMapper bmsTourismProjectActivitiesApplicantMapper;

    @Override
    public List<BmsTourismProjectActivitiesApplicant> getList(BmsTourismProjectActivitiesApplicantParam bmsTourismProjectActivitiesApplicantParam) {
        if (Objects.isNull(bmsTourismProjectActivitiesApplicantParam.getTourismProjectActivitiesId())) {
            return Lists.newArrayList();
        }
        Integer pageNum = bmsTourismProjectActivitiesApplicantParam.getPageNum();
        Integer pageSize = bmsTourismProjectActivitiesApplicantParam.getPageSize();
        if (Objects.nonNull(pageNum) && Objects.nonNull(pageSize)) {
            PageHelper.startPage(pageNum, pageSize);
        }

        BmsTourismProjectActivitiesApplicantExample example = new BmsTourismProjectActivitiesApplicantExample();
        BmsTourismProjectActivitiesApplicantExample.Criteria criteria = example.createCriteria();
        criteria.andIsDelete(0);
        criteria.andTourismProjectActivitiesIdEqualTo(bmsTourismProjectActivitiesApplicantParam.getTourismProjectActivitiesId());
        if (StringUtils.isNotBlank(bmsTourismProjectActivitiesApplicantParam.getUserName())) {
            criteria.andUserNameLike("%" + bmsTourismProjectActivitiesApplicantParam.getUserName() + "%");
        }
        if (StringUtils.isNotBlank(bmsTourismProjectActivitiesApplicantParam.getUserPhone())) {
            criteria.andUserPhoneLike("%" + bmsTourismProjectActivitiesApplicantParam.getUserPhone() + "%");
        }
        if (Objects.nonNull(bmsTourismProjectActivitiesApplicantParam.getUserIdType())) {
            criteria.andUserIdTypeEqualTo(bmsTourismProjectActivitiesApplicantParam.getUserIdType());
        }
        if (StringUtils.isNotBlank(bmsTourismProjectActivitiesApplicantParam.getUserIdCard())) {
            criteria.andUserIdCardLike("%" + bmsTourismProjectActivitiesApplicantParam.getUserIdCard() + "%");
        }
        if (Objects.nonNull(bmsTourismProjectActivitiesApplicantParam.getApplicationTime())) {
            criteria.andApplicationTimeEqualTo(bmsTourismProjectActivitiesApplicantParam.getApplicationTime());
        }
        if (StringUtils.isNotBlank(bmsTourismProjectActivitiesApplicantParam.getStatus())) {
            criteria.andStatusEqualTo(bmsTourismProjectActivitiesApplicantParam.getStatus());
        }

        List<BmsTourismProjectActivitiesApplicant> list = bmsTourismProjectActivitiesApplicantMapper.selectByExample(example);
        return list;
    }

    @Override
    public BmsTourismProjectActivitiesApplicantDetail getItem(Long id) {
        BmsTourismProjectActivitiesApplicant bmsTourismProjectActivitiesApplicant = bmsTourismProjectActivitiesApplicantMapper.selectByPrimaryKey(id);
        BmsTourismProjectActivitiesApplicantDetail detail = new BmsTourismProjectActivitiesApplicantDetail();
        BeanUtils.copyProperties(bmsTourismProjectActivitiesApplicant, detail);
        return detail;
    }

	@Override
	public List<BmsTourismProjectActivitiesApplicant> getExportList(
			BmsTourismProjectActivitiesApplicantParam bmsTourismProjectActivitiesApplicantParam) {

        if (Objects.isNull(bmsTourismProjectActivitiesApplicantParam.getTourismProjectActivitiesId())) {
            return Lists.newArrayList();
        }

        BmsTourismProjectActivitiesApplicantExample example = new BmsTourismProjectActivitiesApplicantExample();
        BmsTourismProjectActivitiesApplicantExample.Criteria criteria = example.createCriteria();
        criteria.andIsDelete(0);
        criteria.andTourismProjectActivitiesIdEqualTo(bmsTourismProjectActivitiesApplicantParam.getTourismProjectActivitiesId());
        if (StringUtils.isNotBlank(bmsTourismProjectActivitiesApplicantParam.getUserName())) {
            criteria.andUserNameLike("%" + bmsTourismProjectActivitiesApplicantParam.getUserName() + "%");
        }
        if (StringUtils.isNotBlank(bmsTourismProjectActivitiesApplicantParam.getUserPhone())) {
            criteria.andUserPhoneLike("%" + bmsTourismProjectActivitiesApplicantParam.getUserPhone() + "%");
        }
        if (Objects.nonNull(bmsTourismProjectActivitiesApplicantParam.getUserIdType())) {
            criteria.andUserIdTypeEqualTo(bmsTourismProjectActivitiesApplicantParam.getUserIdType());
        }
        if (StringUtils.isNotBlank(bmsTourismProjectActivitiesApplicantParam.getUserIdCard())) {
            criteria.andUserIdCardLike("%" + bmsTourismProjectActivitiesApplicantParam.getUserIdCard() + "%");
        }
        if (Objects.nonNull(bmsTourismProjectActivitiesApplicantParam.getApplicationTime())) {
            criteria.andApplicationTimeEqualTo(bmsTourismProjectActivitiesApplicantParam.getApplicationTime());
        }
        if (StringUtils.isNotBlank(bmsTourismProjectActivitiesApplicantParam.getStatus())) {
            criteria.andStatusEqualTo(bmsTourismProjectActivitiesApplicantParam.getStatus());
        }

        List<BmsTourismProjectActivitiesApplicant> list = bmsTourismProjectActivitiesApplicantMapper.selectByExample(example);
        return list;
    
	}
}
